#include <iostream>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

int nod(int a, int b) {
    if (a == std::numeric_limits<int>::max() || a == 0) return b;
    if (b == std::numeric_limits<int>::max() || b == 0) return a;
    
    if (a < 0) a*=-1;
    if (b < 0) b*=-1;
    
    while (a > 0 && b > 0) {
          if (a > b) { a = a - (a / b) * b; }
          else { b = b - (b / a) * a;}
    }

    return (a > 0) ? a : b;
}

void buildTree(vector<int>& segmentTree, int size) {
    int n = (1 << ((int)(log((double)(size - 1)) / log(2.0)) + 1));
    segmentTree.resize(2 * n, std::numeric_limits<int>::max());

    for (int i = n ; i < 2 * n; ++i) {
        segmentTree[i] = segmentTree[i - n + 1];
    }
    segmentTree[2*n - 1] = segmentTree[n];

    for (int i = n - 1; i > 0; ++i) {
        segmentTree[i] = nod(segmentTree[2 * i], segmentTree[2 * i + 1]);
    }
}

int rmq(vector<int>& segmentTree, int l, int r){
    int ans = std::numeric_limits<int>::max();

    int n = segmentTree.size() / 2;
    l += n - 1;
    r += n - 1;

    while (l <= r){
        if (l % 2 != 0) ans = nod(ans, segmentTree[l]);
        if (r % 2 == 0) ans = nod(ans, segmentTree[r]);
        l = (l + 1) / 2;
        r = (r - 1) / 2;
    }

    return ans;
}

int main() {
    if(freopen("in.txt", "r", stdin)==NULL) {
        cout<<"Error: input file can't be opened";
        return 1;
    }
    if(freopen("out.txt", "w", stdout)==NULL) {
        cout<<"Error: output file can't be opened";
        return 1;
    }

    vector<int> segmentTree;
    int n, a, b;
    cin>>n;
    segmentTree.push_back(0);
    for (int i = 0; i < n; ++i) {
        cin>>a;
        segmentTree.push_back(a);
    }
    buildTree(segmentTree, n);

    size_t amountOfRequests;
    cin>>amountOfRequests;

    for (int i=0; i < amountOfRequests; ++i) {
        cin>>a>>b;
        if (a > 0 && b <= n ) {
            cout<<rmq(segmentTree, a, b)<<endl;
        } else {
            cout<<"Error: invalid index"<<endl;
        }
    }

    system("pause");
    return 0;
}